package com.gpj.netty.demo.bio;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @className BIOSocketClient
 * @description
 *   BIO通信模式的客户端代码
 * @author GPJ
 * @date 2021/1/29 22:54
 * @version 1.0
 **/
@Slf4j
public class BIOSocketClient {
	public static void main(String[] args) throws IOException {
		Socket socket = new Socket("127.0.0.1", 9999);

		socket.getOutputStream().write("$客户端请求$".getBytes());
		socket.getOutputStream().flush();

		log.info("已经向服务端发出请求");

		byte[] datas = new byte[1024];
		int num = socket.getInputStream().read(datas);
		if(num != -1){
			log.info("接收到服务端的响应:[{}]", new String(datas, 0, num, StandardCharsets.UTF_8));
		}

		socket.close();
	}
}
